package com.kisszpy.core;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.apache.struts2.util.ServletContextAware;

import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport implements ServletRequestAware,ServletResponseAware,SessionAware,ServletContextAware{

	private static final long serialVersionUID = -5604512411710372586L;
	// 分页默认参数
	private Integer pageNow = 1;
	private Integer pageSize = 20;
	
	protected Map<String, Object> session = new HashMap<String, Object>();
	protected HttpServletRequest request;
	protected HttpServletResponse response;
	protected ServletContext application;
	public void setSession(Map<String, Object> arg0) {
		this.session = arg0;
	}

	public void setServletContext(ServletContext arg0) {
		this.application = arg0;
	}

	public void setServletResponse(HttpServletResponse arg0) {
		this.response = arg0;
	}

	public void setServletRequest(HttpServletRequest arg0) {
		this.request = arg0;
	}
	public void renderJSON(String value){
		response.setCharacterEncoding("utf-8");
		try {
			response.getWriter().print(value);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@SuppressWarnings("unchecked")
	public Map<String,Object> getParams(){
		return this.request.getParameterMap();
	}

	public Integer getPageNow() {
		return pageNow;
	}

	public void setPageNow(Integer pageNow) {
		this.pageNow = pageNow;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
}
